<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class RecBigBillModel extends BaseModel
{
    use HasFactory;

    protected $table = 't_rec_big_bill';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    const BILL_WATI_SUBMIT = 1;     //待审核
    const BILL_WAIT_AUDIT = 2;      //待发送
    const BILL_WAIT_SEND = 3;       //审核失败
    const BILL_WAIT_CONFIRM = 4;    //待确认
    const BILL_CONFIRMED = 5;       //已确认锁账
    const BILL_REJECTED = 6;        //被客户驳回
    const BILL_PARTIAL_PAID = 7;    //部分收款
    const BILL_PAID = 8;            //已收款
    const BILL_WAIT_WRITE_OFF = 9;  //待核销
    const BILL_WRITE_OFF = 10;  //已核销
    const BILL_STATUS_MAPS = [
        self::BILL_WATI_SUBMIT => '待审核',
        self::BILL_WAIT_AUDIT => '待发送',
        self::BILL_WAIT_SEND => '审核失败',
        self::BILL_WAIT_CONFIRM => '待确认',
        self::BILL_CONFIRMED => '客户已确认',
        self::BILL_REJECTED => '被客户驳回',
        self::BILL_PARTIAL_PAID => '部分收款',
        self::BILL_PAID => '已收款',
        self::BILL_WAIT_WRITE_OFF => '待核销',
    ];

    //开票状态 1未开票 2部分开票 3已开票
    const TICKET_NOT_ISSUED = 1;
    const TICKET_PARTIALLY_ISSUED = 2;
    const TICKET_ISSUED = 3;
    const TICKET_STATUS_MAPS = [
        self::TICKET_NOT_ISSUED => '未开票',
        self::TICKET_PARTIALLY_ISSUED => '部分开票',
        self::TICKET_ISSUED => '已开票',
    ];


    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //客户
    public function customer(): BelongsTo {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }
    

    //开票/收款
    public function ticket(): HasMany {
        return $this->hasMany(RecBillTicketModel::class, 'rec_bill_id');
    }

    //提单id
    public function take_order_ids(): HasMany {
        return $this->hasMany(RecBillIdsModel::class, 'rec_bill_id');
    }

}
